/*
 * ArCoLIVECaptureDevice.java
 *
 * Created on 20 de Outubro de 2005, 17:38
 *
 * To change this template, choose Tools | Options and locate the template under
 * the Source Creation and Management node. Right-click the template and choose
 * Open. You can then make changes to the template in the Source Editor.
 */

package br.ufal.tci.nexos.arcolive.beans;

import java.io.Serializable;
import java.util.Vector;
import javax.media.CaptureDeviceInfo;
import javax.media.CaptureDeviceManager;
import javax.media.Format;
import javax.media.MediaLocator;

/**
 * @author <a href="mailto:felipe@labpesquisas.tci.ufal.br">Felipe Barros Pontes</a>.
 * @author <a href="mailto:leandro@labpesquisas.tci.ufal.br">Leandro Melo de
 *         Sales</a>.
 */
public class CaptureDevice implements Serializable {

	/**
	 * 
	 */
	public CaptureDevice() {
	}

	/**
	 * @return
	 */
	public CaptureDeviceInfo[] getDevicesList() {
		Vector captureDevices = CaptureDeviceManager.getDeviceList(null);
		int captureDevicesSize = captureDevices.size();
		CaptureDeviceInfo[] captureDevicesInfo = new CaptureDeviceInfo[captureDevicesSize];
		for (int i = 0; i < captureDevicesSize; i++) {
			captureDevicesInfo[i] = (CaptureDeviceInfo) captureDevices.get(i);
		}
		return captureDevicesInfo;
	}

	/**
	 * @param format
	 * @return
	 */
	public CaptureDeviceInfo[] getDevicesList(Format format) {
		Vector captureDevices = CaptureDeviceManager.getDeviceList(format);
		int captureDevicesSize = captureDevices.size();
		CaptureDeviceInfo[] captureDevicesInfo = new CaptureDeviceInfo[captureDevicesSize];
		for (int i = 0; i < captureDevicesSize; i++) {
			captureDevicesInfo[i] = (CaptureDeviceInfo) captureDevices.get(i);
		}
		return captureDevicesInfo;
	}

	/**
	 * @param deviceName
	 * @return
	 */
	public CaptureDeviceInfo getDevice(String deviceName) {
		return CaptureDeviceManager.getDevice(deviceName);
	}

	/**
	 * @return
	 */
	public String[] getAllDevicesName() {
		CaptureDeviceInfo[] captureDevicesInfo = this.getDevicesList();
		int captureDevicesInfoLength = captureDevicesInfo.length;
		String[] devicesName = new String[captureDevicesInfoLength];
		for (int i = 0; i < captureDevicesInfoLength; i++) {
			devicesName[i] = captureDevicesInfo[i].getName();
		}
		return devicesName;
	}

	/**
	 * @return
	 */
	public MediaLocator[] getAllMediaLocators() {
		CaptureDeviceInfo[] captureDevicesInfo = this.getDevicesList();
		int captureDevicesInfoLength = captureDevicesInfo.length;
		MediaLocator[] mediaLocators = new MediaLocator[captureDevicesInfoLength];
		for (int i = 0; i < captureDevicesInfoLength; i++) {
			mediaLocators[i] = captureDevicesInfo[i].getLocator();
		}
		return mediaLocators;
	}

}